let totalGems = randomNumberOfGems
var gemCounter = 0

func moveCollect() {
    moveForward()
    if isOnGem && gemCounter != totalGems {
        collectGem()
        gemCounter += 1
    }
}

func turnAround() {
    turnLeft()
    turnLeft()
}

func checkColumn() {
    for i in 1...7 {
        moveCollect()
        
        if isBlocked {
            turnAround()
        }
    }
}

moveForward()
pinkPortal.isActive = false
checkColumn()
pinkPortal.isActive = true
moveForward()

pinkPortal.isActive = false
bluePortal.isActive = false

for i in 1...5 {
    moveCollect()
    
    if isBlocked {
        turnAround()
    }
}

bluePortal.isActive = true
moveForward()
bluePortal.isActive = false
checkColumn()